// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Layout from './App.vue'
import VueLazyload from 'vue-lazyload'
import store from './store/store'
import  {fetchData,format}  from "../src/public/tools"
import IMSDK_Config from '@/assets/js/IM_config'
import message from './components/message'

Vue.config.productionTip = false

Vue.use(ElementUI)
Vue.use(VueLazyload)
Vue.prototype.format = format
Vue.prototype.https = fetchData
Vue.prototype.$toast = message.installMessage

// 初始化IMSDK
;(function(){
  IMSDK.setDebugEnable(false);
  IMSDK.callback_log = IMSDK_Config.log;
  IMSDK.callback_showChatMessage = IMSDK_Config.showChatMessage;
  IMSDK.callback_afterLoginSucess = IMSDK_Config.afterLoginSucess;
  IMSDK.callback_afterLoginFailed = IMSDK_Config.afterLoginSucessFailed;
  IMSDK.callback_disconnected = IMSDK_Config.afterDisconnected;
  IMSDK.callback_reconnectSucess = IMSDK_Config.afterReconnectSucess;
})()

//计划推荐websocket
function randomString(len) {
  var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  var maxPos = $chars.length;
  var pwd = '';
  for (var i = 0; i < len; i++) {
      pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}

var ws = new WebSocket('ws://47.96.115.178:1236');
ws.onopen = function(){
  var uid = randomString(32);
  ws.send(uid);
};
ws.onmessage = function(e){
  if(e.data.length>32){
      let tpinfo = JSON.parse(e.data);
      tpinfo.data.short_expect =  parseInt(tpinfo.data.short_expect) +1
      store.commit("getTypeMessage", tpinfo);
    }
};



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { Layout },
  template: '<Layout/>'
})
